home *** CD-ROM | disk | FTP | other *** search
/ Great Canadian Scientists / GCS_CD.iso / mac / PC / GCSData / databa_o.dxr / 00047_Find Scripts.ls < prev    next >
Encoding:
Text File  |  1996-09-21  |  6.9 KB  |  265 lines

  1. on FindUpdate
  2.   global OldLineNum, OldCharNum, WordsField, Update, ManBold, ManBoldLine, ManBoldField
  3.   if ManBold = 1 then
  4.     set the textStyle of line ManBoldLine of field ManBoldField to "Plain"
  5.     set ManBold to 0
  6.   end if
  7.   if Update = 0 then
  8.     exit
  9.   end if
  10.   set CharNum to the length of field "Entry"
  11.   set height to the textHeight of field WordsField
  12.   if (OldCharNum > CharNum) and (field "Entry" <> EMPTY) then
  13.     if (OldLineNum = 1) or (char 1 to CharNum of line OldLineNum - 1 of field WordsField <> field "Entry") then
  14.       if not NoMoreWords(CharNum, OldLineNum) then
  15.       end if
  16.     else
  17.       UnhiliteLine(OldLineNum)
  18.       set OldLineNum to 0
  19.     end if
  20.   end if
  21.   if field "Entry" = EMPTY then
  22.     UnhiliteLine(OldLineNum)
  23.     set OldLineNum to 0
  24.   end if
  25.   if CharNum = 1 then
  26.     BSuspend(21, 22)
  27.     if char 1 of field "Entry" <= "l" then
  28.       go("Find1")
  29.     end if
  30.     if char 1 of field "Entry" >= "m" then
  31.       go("Find2")
  32.     end if
  33.   end if
  34.   if field "Entry" <> EMPTY then
  35.     set LineNum to PickLine(OldLineNum)
  36.     if LineNum <> OldLineNum then
  37.       UnhiliteLine(OldLineNum)
  38.       if LineNum <> 0 then
  39.         HiliteLine(LineNum)
  40.       end if
  41.     end if
  42.     if OldLineNum <> LineNum then
  43.       if LineNum <> 0 then
  44.         set the scrollTop of member WordsField to (LineNum - 1) * height
  45.       end if
  46.     end if
  47.     set OldLineNum to LineNum
  48.     set OldCharNum to CharNum
  49.   else
  50.     set the scrollTop of member WordsField to 0
  51.   end if
  52. end
  53.  
  54. on FindEnterWord
  55.   global OldLineNum, WordsField, Update
  56.   if the key = RETURN then
  57.     if field "Entry" <> EMPTY then
  58.       if Update = 1 then
  59.         DisplayResults(Search(line OldLineNum of field WordsField))
  60.       else
  61.         DisplayResults(Search(field "Entry"))
  62.       end if
  63.     else
  64.       beep()
  65.     end if
  66.     dontPassEvent()
  67.   end if
  68. end
  69.  
  70. on NoMoreWords CharNum, LineNum
  71.   global WordsField
  72.   set Temp to 0
  73.   set LineNum to LineNum + 1
  74.   set len to the length of field "Entry"
  75.   if char 1 to len of line LineNum of field WordsField <> field "Entry" then
  76.     set Temp to 1
  77.   else
  78.     set Temp to 0
  79.   end if
  80.   return Temp
  81. end
  82.  
  83. on PickLine StartLine
  84.   global PickLineResult, WordsField
  85.   if StartLine = 0 then
  86.     set StartLine to 1
  87.   end if
  88.   set len to the length of field "Entry"
  89.   if char 1 to len of line StartLine of field WordsField = field "Entry" then
  90.     return StartLine
  91.   end if
  92.   set PickLineResult to 0
  93.   set Num to the number of lines in field WordsField
  94.   PickLineHelp(field "Entry", 1, Num)
  95.   repeat while (char 1 to len of line PickLineResult of field WordsField > field "Entry") or (char 1 to len of line PickLineResult of field WordsField = field "Entry")
  96.     set Temp to PickLineResult
  97.     set PickLineResult to PickLineResult - 10
  98.     if Temp <= 1 then
  99.       exit repeat
  100.     end if
  101.   end repeat
  102.   set PickLineResult to Temp
  103.   set Temp2 to PickLineResult
  104.   repeat while char 1 to len of line PickLineResult of field WordsField = field "Entry"
  105.     set Temp to PickLineResult
  106.     set PickLineResult to PickLineResult - 1
  107.     if Temp <= 1 then
  108.       exit repeat
  109.     end if
  110.   end repeat
  111.   return Temp
  112. end
  113.  
  114. on PickLineHelp key, min, max
  115.   global PickLineResult, WordsField
  116.   set len to the length of field "Entry"
  117.   set Mid to ((max - min) / 2) + min
  118.   if char 1 to len of line Mid of field WordsField = key then
  119.     set PickLineResult to Mid
  120.     exit
  121.   end if
  122.   if char 1 to len of line min of field WordsField = key then
  123.     set PickLineResult to min
  124.     exit
  125.   end if
  126.   if char 1 to len of line max of field WordsField = key then
  127.     set PickLineResult to max
  128.     exit
  129.   end if
  130.   if (min + 1) = max then
  131.     set PickLineResult to 0
  132.     exit
  133.   end if
  134.   if char 1 to len of line Mid of field WordsField > key then
  135.     PickLineHelp(key, min, Mid)
  136.     exit
  137.   end if
  138.   if char 1 to len of line Mid of field WordsField < key then
  139.     PickLineHelp(key, Mid, max)
  140.     exit
  141.   end if
  142. end
  143.  
  144. on ChangeWord CharNum, LineNum
  145.   global WordsField
  146.   set ReturnVal to 0
  147.   if char CharNum of line LineNum of field WordsField <> char CharNum of field "Entry" then
  148.     set ReturnVal to 1
  149.   end if
  150.   return ReturnVal
  151. end
  152.  
  153. on HiliteLine LineNum
  154.   global WordsField
  155.   set the textStyle of line LineNum of field WordsField to "Bold"
  156. end
  157.  
  158. on UnhiliteLine LineNum
  159.   global WordsField
  160.   set the textStyle of line LineNum of field WordsField to "Plain"
  161. end
  162.  
  163. on Search key
  164.   global SearchResult, SearchIndex
  165.   set SearchResult to 0
  166.   set Num to the number of lines in SearchIndex
  167.   SearchHelp(key, 1, Num)
  168.   if value(SearchResult) = 0 then
  169.     beep()
  170.   end if
  171.   return value(SearchResult)
  172. end
  173.  
  174. on SearchHelp key, min, max
  175.   global SearchResult, SearchIndex
  176.   set Mid to ((max - min) / 2) + min
  177.   if item 1 of line Mid of SearchIndex = key then
  178.     set SearchResult to Mid
  179.     exit
  180.   end if
  181.   if item 1 of line max of SearchIndex = key then
  182.     set SearchResult to max
  183.     exit
  184.   end if
  185.   if item 1 of line min of SearchIndex = key then
  186.     set SearchResult to min
  187.     exit
  188.   end if
  189.   if (min + 1) = max then
  190.     exit
  191.   end if
  192.   if item 1 of line Mid of SearchIndex > key then
  193.     SearchHelp(key, min, Mid)
  194.     exit
  195.   end if
  196.   if item 1 of line Mid of SearchIndex < key then
  197.     SearchHelp(key, Mid, max)
  198.     exit
  199.   end if
  200. end
  201.  
  202. on DisplayResults LineNum
  203.   global SearchIndex
  204.   if LineNum = 0 then
  205.     put EMPTY into field "Results"
  206.     exit
  207.   end if
  208.   set lineCount to 1
  209.   set Temp to EMPTY
  210.   set ItemLine to line LineNum of SearchIndex
  211.   repeat with count = 2 to the number of items in ItemLine
  212.     put line value(item count of ItemLine) of field "Scientist Order" into line lineCount of Temp
  213.     set lineCount to lineCount + 1
  214.   end repeat
  215.   put Temp into field "Results"
  216.   set the scrollTop of member "Results" to 0
  217. end
  218.  
  219. on PrepFind
  220.   global SearchIndex
  221.   set SearchIndex to field "Search1"
  222.   set SearchIndex to SearchIndex & RETURN & field "Search2"
  223.   set the textHeight of field "Words1" to 14
  224.   set the textHeight of field "Words2" to 14
  225. end
  226.  
  227. on FixIndexList fname
  228.   set count to 1
  229.   repeat while line count of field fname <> EMPTY
  230.     put count
  231.     set Current to item 1 of line count of field fname
  232.     if item 1 of line count + 1 of field fname = Current then
  233.       repeat with Count2 = 2 to the number of items in line count + 1 of field fname
  234.         set Temp to 0
  235.         repeat with Count3 = 2 to the number of items in line count of field fname
  236.           if item Count2 of line count + 1 of field fname = item Count3 of line count of field fname then
  237.             set Temp to 1
  238.           end if
  239.         end repeat
  240.         if Temp = 0 then
  241.           put item Count2 of line count + 1 of field fname into item the number of items in line count of field fname + 1 of line count of field fname
  242.         end if
  243.       end repeat
  244.       delete line count + 1 of field fname
  245.       next repeat
  246.     end if
  247.     set count to count + 1
  248.   end repeat
  249.   beep()
  250.   beep()
  251.   beep()
  252. end
  253.  
  254. on extract
  255.   repeat with count = 1 to 146
  256.     put the name of cast (count + 300) into line count of field "Scientist Order"
  257.   end repeat
  258. end
  259.  
  260. on DoIt
  261.   FixIndexList("Search1")
  262.   FixIndexList("Search2")
  263.   alert("DONE!!")
  264. end
  265.